package com.ruoyi.web.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.w3c.dom.NodeList;

import com.ruoyi.supervise.domain.RelatedDesignUnits;
import com.ruoyi.web.vo.XmlVO;

import cn.hutool.core.util.XmlUtil;

public class XmlNodeUtil {

	public static List<XmlVO> getXmlNode3(String strXml, XmlVO vo,String node) throws Exception {
		Document doc = null;
		List<XmlVO> list = new ArrayList<XmlVO>();

		doc = DocumentHelper.parseText(strXml);// 将字符串转为XML
		Element rootElt = doc.getRootElement();// 获取根节点 rootElt.getName()拿根节点的名称
		if(node.equals("Representative")) {
			Iterator iter = rootElt.elementIterator(node);// 获取根节点下的子节点node
			while (iter.hasNext()) {// 遍历node节点
				XmlVO xvo = new XmlVO();
				Element recordElec = (Element) iter.next();
				String name = recordElec.elementTextTrim(vo.getName());
				String guid = recordElec.elementTextTrim(vo.getGuid());
				String certificateNum = recordElec.elementTextTrim(vo.getCertificateNum());
				String title = recordElec.elementTextTrim(vo.getTitle());
				String idnumber = recordElec.elementTextTrim(vo.getIDNumber());
				xvo.setName(name);
				xvo.setCertificateNum(certificateNum);
				xvo.setGuid(guid);
				xvo.setIDNumber(idnumber);
				xvo.setTitle(title);
				list.add(xvo);
			}
		}else {
			Iterator iter = rootElt.elementIterator(node);// 获取根节点下的子节点RegistNames
			while (iter.hasNext()) {// 遍历RegistNames节点
				Element recordEle = (Element) iter.next();
				Iterator itera = recordEle.elementIterator("FDataList");
				while (itera.hasNext()) {
					Element recordElea = (Element) itera.next();
					Iterator iterb = recordElea.elementIterator("Person");
					while (iterb.hasNext()) {
						XmlVO xvo = new XmlVO();
						Element recordElec = (Element) iterb.next();
						String name = recordElec.elementTextTrim(vo.getName());
						String guid = recordElec.elementTextTrim(vo.getGuid());
						String certificateNum = recordElec.elementTextTrim(vo.getCertificateNum());
						String title = recordElec.elementTextTrim(vo.getTitle());
						String idnumber = recordElec.elementTextTrim(vo.getIDNumber());
						xvo.setName(name);
						xvo.setCertificateNum(certificateNum);
						xvo.setGuid(guid);
						xvo.setIDNumber(idnumber);
						xvo.setTitle(title);
						list.add(xvo);
					}
				}
			}
		}
		
		return list;

	}
	
	
	
}
